package com.petmall.mapper;

import com.petmall.entity.User_gold_detail;
import com.petmall.entity.User_level_detail;
import com.petmall.entity.User_md5;
import org.apache.ibatis.annotations.*;
import com.petmall.entity.User;

import java.util.List;

/**
 * Created by pig2guang on 2017/4/3.
 */
@Mapper
public interface UserMapper {

    @Select("select * from tb_user where id = #{id}")
    public User selectById(long id);

    @Select("select * from tb_user where phone = #{phone} ")
    public User selectByPhone(String phone);

    @Select("select * from tb_user where username = #{username} and password = #{password}")
    public User selectByPassword(@Param("username") String username, @Param("password") String password);

    @Insert("insert into tb_user(username,password,phone,head_portrait,level) values(#{username}, #{password}, #{phone}, #{head_portrait}, #{level})")
    public void insertUser(@Param("username") String username, @Param("password") String password, @Param("phone") String phone, @Param("head_portrait") String head_portrait, @Param("level") String level);

    @Update("update tb_user set username = #{username}, email = #{email}, realname = #{realname}, sex = #{sex}, birthday = #{birthday} where id = #{user_id}")
    public void updateUserByUserId(@Param("user_id") long user_id, @Param("username") String username, @Param("email") String email, @Param("realname") String realname, @Param("sex") String sex, @Param("birthday") String birthday);

    @Update("update tb_user set level = #{level}, level_value = level_value + #{level_value}, gold_num = gold_num + #{gold_num} where id = #{user_id}")
    public void updateLevelGold(@Param("user_id") long user_id, @Param("level") String level, @Param("level_value") int level_value, @Param("gold_num") int gold_num);

    @Select("select * from tb_user_level_detail where user_id = #{user_id}")
    public List<User_level_detail> selectLevelDetail(long user_id);

    @Select("select * from tb_user_gold_detail where user_id = #{user_id}")
    public List<User_gold_detail> selectGoldDetail(long user_id);

    @Insert("insert into md5_user(username,password) values(#{username}, #{password})")
    public void insertMd5User(@Param("username") String username, @Param("password") String password);

    @Select("select * from md5_user where username = #{username} and password = #{password}")
    public User_md5 selectMd5User(@Param("username") String username, @Param("password") String password);

    @Select("select * from md5_user where username = #{username}")
    public User_md5 selectMd5UserByUserName(@Param("username") String username);

}
